﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using HeartLess.LevelData;

namespace HeartLess.GameObjects
{
    public abstract class GameObject
    {
        private Vector2 _location;
        private bool _dead = false;

        public Vector2 Location
        {
            get { return _location;}
            protected set
            {
                _location = value;
                UpdateBounds();
            }
        }

        public Rectangle Bounds
        {
            get;
            private set;
        }

        public bool Dead
        {
            get
            {
                return _dead;
            }
            protected set
            {
                _dead = value;
            }
        }

        /// <summary>
        /// Create a game object without a location. This does not get drawn until the location has been set.
        /// </summary>
        public GameObject()
        {
            //do nothing
        }

        /// <summary>
        /// Create a game object with a pixel-based location
        /// </summary>
        /// <param name="location"></param>
        public GameObject(Vector2 location)
        {
            this.Location = location;
            UpdateBounds();
        }

        /// <summary>
        /// Create a game object with a grid-based location
        /// </summary>
        /// <param name="location"></param>
        public GameObject(Point gridLocation)
        {
            this.Location = Level.getLocationFromGridPoint(gridLocation);
        }

        public abstract void Update(GameTime gameTime);

        public abstract void Draw(SpriteBatch spriteBatch);

        private void UpdateBounds()
        {
            Bounds = new Rectangle((int)Location.X + 4, (int)Location.Y+2, Level.UNIT_PIXEL_SIZE - 8, Level.UNIT_PIXEL_SIZE-2);
        }
    }
}
